package com.cybertooth.dbconvenience.query.columns;

import com.cybertooth.dbconvenience.query.core.SqlTransformer;
import org.apache.commons.lang.StringUtils;

/**
 * <p></p>
 *
 * @author dnelson
 */
public class Column implements SqlTransformer {
	// -----------------------------------------------------------------------Fields

	protected String prefix;
	protected String name;

	// -------------------------------------------------------------------Properties

	public String getName() {
		return name;
	}

	public String getPrefix() {
		return prefix;
	}

	// -----------------------------------------------------------------Constructors

	public Column(String name) {
		this.name = name;
	}

	public Column(String prefix, String name) {
		this.prefix = prefix;
		this.name = name;
	}

	// ---------------------------------------------------------------Public Methods

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toSql() {
		String prefix = StringUtils.isBlank(this.prefix) ? "" : this.prefix + ".";
		return new StringBuilder()
				.append(" ")
				.append(prefix).append(this.name)
				.append(" ")
				.toString();
	}
}
